package cn.wolfcode.mq;

import cn.wolfcode.common.exception.BusinessException;
import cn.wolfcode.service.IOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "OrderTimeOutListener",
        topic = MQConstant.ORDER_PAY_TIMEOUT_TOPIC
)
public class OrderTimeOutListener implements RocketMQListener<OrderMQResult> {
    @Autowired
    private IOrderInfoService orderInfoService;

    @Override
    public void onMessage(OrderMQResult message) {
        //订单取消逻辑
        try {
            System.out.println("处理订单超时逻辑");
            //message:seckillId time token orderNo
            orderInfoService.cancelOrder(message);
        } catch (BusinessException e) {
            //当方法抛出BusinessException,属于正常流程,记录一下,让消息消费掉.
            e.printStackTrace();
        }
    }
}
